home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / doc / COMPILER.DOC < prev    next >
Text File  |  1994-02-13  |  16KB  |  385 lines

  1.  
  2. compiler/compiler                        compiler/compiler
  3. compiler/COMPILER                        compiler/COMPILER
  4.  
  5.                 DICE SYSTEM
  6.  
  7.                   Matthew Dillon
  8.                   891 Regal Rd.
  9.                   Berkeley, Ca. 94708
  10.                   USA
  11.  
  12.                   dillon@overload.Berkeley.CA.US
  13.                   uunet.uu.net!overload!dillon
  14.  
  15.                   BIX: mdillon
  16.  
  17.             COMPILER FEATURES LIST AND ORGANIZATION
  18.  
  19.             NOTE: net distributed releases will not contain
  20.               commodore includes or amiga*.lib
  21.  
  22.     (1) Organization of includes and libraries, default:
  23.  
  24.     DINCLUDE:        location of top level includes such as stdio.h
  25.  
  26.     DINCLUDE:Amiga13/   location of 1.3 amiga includes, -1.3 option must
  27.                 be used with DCC or set in ENV:DCCOPTS
  28.  
  29.     DINCLUDE:Amiga20/   location of 2.0 amiga includes, -2.0 option must
  30.                 be used with DCC or set in ENV:DCCOPTS
  31.  
  32.  
  33.     NOTE !!! Amiga 1.3 and 2.0 includes should be placed in the
  34.     subdirectory dinclude:Amiga13 and dinclude:amiga20, that is,
  35.     dinclude:Amiga13/Exec/*.h, dinclude:Amiga13/graphics/*.h, etc...
  36.  
  37.     DCC references startup and libraries to DLIB:
  38.  
  39.     DLIB:amigas13.lib   A small-data model version of the 1.3 AMIGA.LIB
  40.     DLIB:amigas20.lib   A small-data model version of the 2.0 AMIGA.LIB
  41.     DLIB:cs.lib        The main C library for which you have source code
  42.     DLIB:ms.lib        The math library
  43.     DLIB:auto.lib        The auto library-open library
  44.     DLIB:c.o        The startup module
  45.     DLIB:x.o        The terminator module
  46.  
  47.     (2) (removed)
  48.  
  49.  
  50.     (3) DCC generated link lines
  51.  
  52.     If you give DICE the following line (assuming DCCOPTS contains the -1.3
  53.     option):
  54.  
  55.     1> DCC foo.o -o foo
  56.  
  57.     It will run DLink with the following options:
  58.  
  59.     DLink dlib:c.o foo.o dlib:cs.lib dlib:amigas13.lib dlib:auto.lib dlib:x.o -o foo
  60.  
  61.     DLIB:C.O        DICE startup code
  62.     FOO.O        your object module(s)
  63.     DLIB:CS.LIB     small data model version of c.lib
  64.     DLIB:AMIGAS13.LIB    small data model version of commodore amiga.lib for 1.3
  65.     DLIB:AUTO.LIB    DICE AUTO.LIB
  66.     DLIB:X.O        DICE section terminator code
  67.  
  68.  
  69.     Some explanation is in order.  AUTO.LIB catches any references to
  70.     common library base variables when no storage has been declared and
  71.     imports code to automatically open said libraries on startup and
  72.     close them on exit.  DICE uses this feature to import code to open
  73.     and close "dos.library" when DOSBase is referenced, and also for
  74.     the floating point libraries.
  75.  
  76.     You, the programmer, can use the feature to simply make arbitrary
  77.     library calls and not have to deal with base variables, openning,
  78.     or closing libraries in your code.  To take advantage of the
  79.     feature simply do not declare library base variables or open/close
  80.     the libraries.
  81.  
  82.     X.O is used to supply an RTS at the end of the special autoinit and
  83.     autoexit sections.  Any module between C.O and X.O may declare
  84.     these special sections to handle run-time relocations and other
  85.     DICE features, and do so such that when the base of the section is
  86.     JSR'd all the various module's code is sequenced through until the
  87.     RTS in X.O is hit for the sections in question.
  88.  
  89.  
  90.     (4) SMALL DATA AMIGA.LIB
  91.  
  92.     DICE uses a small-data model version of Commodore's AMIGA.LIB to
  93.     allow it to generate residentable executables (-r option to DCC).
  94.     The small data amiga.lib, called AMIGAS13.LIB (note the 's') is
  95.     generated from the large modem amiga.lib with the LIBTOS program.
  96.     (under 2.0 it's AMIGAS20.LIB)
  97.  
  98.     The source to the LIBTOS program is available to allow developers
  99.     using DICE to add new base variables to LIBTOS's search list when
  100.     new operating systems come out without having to wait for my
  101.     update.
  102.  
  103.     WARNING!!  Commodore screwed up the var-args entry points in the
  104.     2.0 amiga.lib, such as CreateNewProcTags().  To ensure that you get
  105.     tags that work properly, you must remake the 2.0 's' library from
  106.     the library source archive after installing updates from commodore.
  107.     The DICE library source overides these var-args tags with ones that
  108.     work.
  109.  
  110.     ----------------------------------------------------------------------
  111.  
  112.                 COMPILER FEATURES LIST
  113.  
  114.     (0) ANSI.  Pretty much ansi.  Please report non-ansism problems.  Check
  115.     out the doc/KnownBugs list before reporting a problem.
  116.  
  117.     (1) autos are placed in registers based on weighted usage.  A0,A1,D0,D1
  118.     will be used as register variables whenever possible, which usually
  119.     reduces the number of registers that must be saved/restored in
  120.     critical low level routines.  The 'register' keyword is essentially
  121.     ignored but does add some weight to the variable for register
  122.     selection.  If you do not wish a variable to be placed in a register,
  123.     use the volatile storage qualifier when declaring the variable.
  124.  
  125.     (2) LINK/UNLK is removed from low level routines that do not reference
  126.     A5 and do not make any subroutine calls.
  127.  
  128.     (3) MOVEM is converted to MOVE or deleted entirely when possible.
  129.  
  130.     (4) Various obvious optimizations:  use of BSET, BCLR, BTST as short
  131.     cuts to logic operations, CMP/TST, etc...
  132.  
  133.     (5) Switch() statements are optimized as follows:
  134.  
  135.         * if the range of values is less than double the number of cases
  136.           a lookup table will be used
  137.  
  138.         * if a small number of cases exists a sub[q]/beq sequence
  139.           will be used
  140.  
  141.         * for a sufficiently large set of cases that cannot be made
  142.           into a jump table, a binary subdivision method is used
  143.           allowing huge switches to be processed very quickly.
  144.  
  145.     (6) Branch optimization.  Bxx to BRAs are optimized (up to 20 hops) by
  146.     DAS, and massive optimization is done to multi-level conditionals
  147.     by the main compiler pass.  branches to the next instruction are
  148.     deleted entirely.
  149.  
  150.     (7) Workbench support.  The standard startup module supports the workbench.
  151.     Specifically, the low level _main() in c.o does this.
  152.  
  153.     When a program is run from the workbench, a different entry point is
  154.     called:     wbmain(wbmsg)
  155.  
  156.     If you do not supply a wbmain() then the one from the c.lib library
  157.     is used which immediately return(-1)s, exiting the program.
  158.  
  159.     The standard return from wbmain() or using exit() or _exit()
  160.     automatically ReplyMsg()s the workbench message for you, do NOT
  161.     do so manually.
  162.  
  163.     (8) _main() shortcut for extremely low level programs.
  164.  
  165.     REFER TO _MAIN.DOC FOR INFORMATION ON USING THE _main()
  166.     ENTRY POINT INSTEAD OF main().
  167.  
  168.     (9) AutoInit support.  You may qualify a subroutine with the __autoinit
  169.     keyword that will cause it to be automatically called by the
  170.     startup code rather than having to explicitly call it from main.
  171.  
  172.     This feature is more useful to bring code in indirectly.  For
  173.     example, to automatically OpenLibrary() (& CloseLibrary()) floating
  174.     point libraries if their base variables are referenced.  However,
  175.     it can also be used for independant module initialization.  Note
  176.     that stdio is NOT up and running at this time.
  177.  
  178.     Refer to the auto.lib source code for examples.
  179.  
  180.     __autoexit works the same way.    Note that __autoinit routines are
  181.     called BEFORE _main, just after autoinit libraries are openned,
  182.     and __autoexit routines are called in __exit just before autoinit
  183.     libraries are closed.
  184.  
  185.     (10) DCC runs fast.  Make everything resident and watch it fly.  Most
  186.      of this speed comes from loading entire files into memory at once.
  187.      This might present a memory problem, but in general DICE's memory
  188.      usage is comparable to Lattice and Aztec.
  189.  
  190.     (11) CODE SIZE is comparable with Lattice and Aztec, even better in
  191.      many cases.  The minimum program sizes are as follows:
  192.  
  193.     _main() { }          448    no stdio/fd
  194.      main() { }         2736    some stdio
  195.      main() { printf..} 5492    most of stdio
  196.  
  197.     (12) EXTENSIONS , see EXTENSIONS.DOC.  DICE provides many extensions
  198.      to C to support various AMIGAisms and ROM based code, including
  199.      special treatment of the 'const' storage qualifier.
  200.  
  201.     (13) The preprocessor is able to handle arbitrarily sized macros.  There
  202.      are no limits to symbol or macro length.  The preprocessor is able to
  203.      handle up to 64 levels of includes / macro recursions with arbitrary
  204.      use of the string-ize (#) and token pasting (##) operators.
  205.  
  206.      The preprocessor implements the __BASE_FILE__ macro as well as all
  207.      standard ANSI macros (__FILE__, __LINE__, __DATE__, __TIME__, ...)
  208.  
  209.     (14) DICE supports the creation of residentable executables in nearly
  210.      all cases (exception: using the __geta4 procedure qualifier
  211.      precludes being able to make an executable resident, also non
  212.      const __chip data... see EXTENSIONS.DOC)
  213.  
  214.      Not only is residentability supported, but it is supported
  215.      without requiring the programmer to #include all sorts of
  216.      prototype/pragma files.
  217.  
  218.     (15) DICE supports the small-data model, large data model, small and
  219.      large code models, and special data models (word absolute,
  220.      absolute known address) for supporting ROMable code.  The linker
  221.      automatically generates JMP tables when the small-code model is
  222.      used in large executables.
  223.  
  224.     (16) REGISTERED user's DICE supports __chip, __near, and __far keywords,
  225.      as well as many others.
  226.  
  227.     (17) Simplified library and startup module design.  There are no multiple
  228.      versions of a single library for different memory models and the
  229.      frontend, DCC, makes all library and startup module interaction
  230.      except m.lib invisible.  The same c.o handles both resident and
  231.      non-resident startup.    c.lib and m.lib may be used with programs
  232.      that declare more than 64KBytes of BSS (though not with programs
  233.      that declare more than 64KBytes of __near initialized storage).
  234.  
  235.      There is no large-data-model version of c.lib and m.lib,
  236.      although you can easily recompile the libraries into a large-data
  237.      model version if you wish.  I suggest that instead of doing that
  238.      you stick with the small-data model and use the __geta4 type
  239.      qualifier to procedures which are called out of context.
  240.  
  241.      The registered dist contains several source examples for libraries,
  242.      dos handlers, exec devices, and printer drivers.
  243.  
  244.     (18) Optimization of args to prototyped routines
  245.  
  246.  
  247.     --------------------------------------------------------------------------
  248.                     GOALS
  249.  
  250.     In writing DICE my goals are as follows:
  251.  
  252.     - reasonably fast compilation.  Modular executables for ease of use,
  253.       reliability, and testability.
  254.  
  255.     - concentrate more on reliability and less on optimizations.  Remember that
  256.       this is only the third major distribution of DICE, I expect some bugs
  257.       to show up.  I expect to become more reliable than the two other
  258.       commercial C compilers in the Amiga market within a year.
  259.  
  260.     - but do not forget optimizations... put in relatively easy to implement
  261.       optimizations that do not destroy the reliability of DICE.  DICE does
  262.       no common sub-expression or loop unrolling optimizations, but does do
  263.       relatively smart register allocation and multi-level history to
  264.       propogate conditional expressions.
  265.  
  266.     - provide comprehensive support of the Amiga, especially for new
  267.       versions of the OS that come out.  DICE fully supports 1.3 and 2.0
  268.       with an easy extension mechanism to allow development on several
  269.       OS versions / betas simultaniously.
  270.  
  271.     - I have always torn my hair out at not being able to easily fix bugs in
  272.       the support libraries for commercial compilers.  DICE includes full
  273.       source for its support libraries (c.lib, m.lib, auto.lib) and a means
  274.       to remake the library.  DICE also includes full source to some of
  275.       its own utilities, namely LIBTOS and the DCC frontend which are the
  276.       most likely candidates for programmer hair loss.
  277.  
  278.       While you may NOT distribute any source code to non-registered users,
  279.       you can fix bugs you find without having to wait for a new release,
  280.       or add your own features to programs like DCC.
  281.  
  282.     ------------------------------------------------------------------------
  283.                    COMMENTS
  284.  
  285.     Registerized parameteres are now implemented.  The implementation
  286.     turned out to be not all that complex.  However, you cannot as yet
  287.     specify WHICH registers parameters are to be placed for a call.
  288.     Refer to the -mRR option in DCC.DOC
  289.  
  290.     Inline library calls are not implemented.  Inline library calls are
  291.     actually useful and when properly implemented increase efficiency to
  292.     low level calls such as AddHead() and GetMsg().  Other calls such as
  293.     Move() and Draw() do not increase noticably in efficiency. #pragma's
  294.     must be used to define inline calls and this makes the compiler
  295.     enviroment less portable.  Lattice made a big mistake *requiring* the
  296.     use of inline library calls with residentable programs.  My solution
  297.     was to write a program to convert AMIGA**.LIB into a small-data version
  298.     of same called AMIGAS**.LIB.
  299.  
  300.     DICE still uses tags for library calls, but fully registerized tags are
  301.     now available to registered users which significantly reduces library
  302.     call overhead to the point where it's only a few cycles slower than a
  303.     SAS/C inline call, and without the hassle.
  304.  
  305.     Similarly, I have not implemented prototype and amiga-library function
  306.     array support in the compiler or linker but instead have provided
  307.     separate programs to aid in this.  While less automated than SAS/C,
  308.     this support is MUCH more portable and, in my opinion, much cleaner, as
  309.     well as more easily maintained.
  310.  
  311.     In general, I refuse to implement a thousand nearly useless features
  312.     that will only introduce more bugs into the compiler.
  313.  
  314.     ------------------------------------------------------------------------
  315.                 COMPATIBILITY
  316.  
  317.                    ANSI C
  318.  
  319.     With structural returns and auto-aggregate is implemented, DICE is now
  320.     95% ANSI compliant.  Known differences are described in the KNOWNBUGS
  321.     document.
  322.  
  323.     I spent a great deal of time ensuring that STDIO routines run
  324.     relatively fast.  I decided to write nearly all of the support library
  325.     in C instead of falling back to optimized assembly to keep the system
  326.     uniform and portable.  One does not notice much of a difference between
  327.     the C strcpy() and an assembly strcpy() relative to the run time of
  328.     their program.
  329.  
  330.                     AMIGA
  331.  
  332.     As said in feature (7), if you wish your program to be runnable from
  333.     the workbench you must supply a wbmain() entry point.  If you do not
  334.     then running the program from the workbench will result in its
  335.     immediate termination (e.g. nothing happens).  On return from wbmain()
  336.     or exit() the workbench message is automatically ReplyMsg()d by the
  337.     exit code.
  338.  
  339.     DICE separates workbench startup and puts it in the hands of the user
  340.     to simplify the user's code.  Since there are two entry points,
  341.     main() for CLI run programs and wbmain() for WORKBENCH-run programs,
  342.     the programmer can more easily modularize his code.
  343.  
  344.     The Registered release of DICE supports the __near, __far, and __chip
  345.     keywords.
  346.  
  347.                   UNBUFFERED CONSOLE IO
  348.  
  349.     You may set a console to RAW mode using the setbuf() and setvbuf() calls.
  350.     You may set a console back to COOKED mode using the same calls.
  351.  
  352.     ------------------------------------------------------------------------
  353.  
  354.                 Your first program
  355.  
  356.     1> cd examples
  357.     1> dcc hello.c -o ram:hello
  358.     1> ram:hello
  359.     hello world
  360.     1>
  361.  
  362.                 Your first residentable program
  363.  
  364.     1> cd examples
  365.     1> dcc hello.c -o ram:hello -r
  366.     1> ram:hello
  367.     hello world
  368.     1> resident ram:hello
  369.     1> hello        ; instantanious execution
  370.     hello world
  371.     1>
  372.  
  373.     * NOTE, a common problem is that users have removed various floating
  374.     point libraries from LIBS: and this may prevent DC1 from running. Make
  375.     sure you have the full complement of floating point libraries in LIBS:
  376.  
  377.     Another common problem is related to your PATH... if DCC is unable to
  378.     run one of the subprograms (DCPP, DC1, DAS, and DLINK) you may not have
  379.     DCC:BIN in your path.  ARP is known to screw things up in this regard
  380.     and if you are running ARP try de-installing it to see if that was the
  381.     problem.  You cannot use the ARP resident command (ARES) with DICE
  382.     executables.
  383.  
  384.  
  385.